package aaa;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author ：Xiaochen
 * @date ：Created in 2022/11/9 22:53
 * @description：
 * @modified By：
 * @version:
 */
public class ProxyFactory {
    private Haha target;

    public ProxyFactory(Haha target) {
        this.target = target;
    }

    public Heihei getInstance(){

        ClassLoader loader = target.getClass().getClassLoader();
        Class<?>[] interfaces = target.getClass().getInterfaces();
        InvocationHandler h = new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                jiaoYan();
                Object result = method.invoke(target, args);
                System.out.println(result);
                log();
                return result;
            }
        };
        Object o = Proxy.newProxyInstance(loader, interfaces, h);

        return (Heihei) o;
    }
    public void jiaoYan(){
        System.out.println("校验内容");
    }
    public void log(){
        System.out.println("日志");
    }

}